package com.winchain.provider.expiration.service.impl;

import com.shell.bee.acct.account.po.AcctBas;
import com.winchain.chainbill.bill.base.po.CbHldr;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.service.CbHldrService;
import com.winchain.chainbill.bill.base.service.CbRecService;
import com.winchain.chainbill.trade.service.BillAcctService;
import com.winchain.provider.expiration.service.BillExpHldrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("billExpHldrService")
public class BillExpHldrServiceImpl implements BillExpHldrService {
	@Autowired
	private CbHldrService cbHldrService;
	@Autowired
	private BillAcctService billAcctService;
	@Autowired
	private CbRecService cbRecService;

	public String getFocalCoIdByBillId(String billId) {
		CbRec cbRec = (CbRec) this.cbRecService.selectByKey(billId);
		return cbRec.getConfirmerId();
	}

	public String getFocalCoNameByBillId(String billId) {
		CbRec cbRec = (CbRec) this.cbRecService.selectByKey(billId);
		return cbRec.getConfirmerNm();
	}

	public CbHldr getHldr(String billId, int hldrLvl) {
		CbHldr hldr = new CbHldr();
		hldr.setBillId(billId);
		hldr.setHldrLvl(Integer.valueOf(hldrLvl));
		return (CbHldr) this.cbHldrService.selectOne(hldr);
	}

	public AcctBas getDfltSettlAcct(String cusId) {
		return this.billAcctService.getAcctBas(cusId, null, "00");
	}

	public String getFinId(String billId) {
		CbRec cbRec = (CbRec) this.cbRecService.selectByKey(billId);
		return cbRec.getFinId();
	}

	public CbRec getBill(String billId) {
		return (CbRec) this.cbRecService.selectByKey(billId);
	}

	public AcctBas getCashAcct(String finId) {
		return this.billAcctService.getAcctBas(finId, null, "00");
	}

	public AcctBas getInsAcct(String finId) {
		return this.billAcctService.getAcctBas(finId, null, "00");
	}

	public AcctBas getTransientQuotaAcct(String cusId) {
		return this.billAcctService.getAcctBas(cusId, "2", null);
	}

	public AcctBas getTransientChainAcct(String cusId) {
		return this.billAcctService.getAcctBas(cusId, "2", null);
	}

	public AcctBas getCreditQuotaAcct(String cusId) {
		return this.billAcctService.getAcctBas(cusId, "1", null);
	}

	public AcctBas getChainBillAcct(String cusId) {
		return this.billAcctService.getAcctBas(cusId, "1", null);
	}

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public CbHldr getHldrWithNewTx(String billId, int hldrLvl) {
		CbHldr hldr = new CbHldr();
		hldr.setBillId(billId);
		hldr.setHldrLvl(Integer.valueOf(hldrLvl));
		return (CbHldr) this.cbHldrService.selectOne(hldr);
	}
}
